package com.ljf.eslab.lab.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ljf.eslab.lab.vo.LabNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ljf.eslab.lab.entity.LabEntity;
import com.ljf.eslab.lab.service.LabService;
import com.ljf.common.utils.PageUtils;
import com.ljf.common.utils.R;



/**
 * 
 *
 * @author ljf
 * @email ljf@gmail.com
 * @date 2021-05-29 11:03:55
 */
@RestController
@RequestMapping("lab/lab")
public class LabController {
    @Autowired
    private LabService labService;

    /**
     * 列表
     */

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = labService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @Cacheable("labNames")
    @RequestMapping("/listOfName")
    public R listOfName(){
        List<LabNameVo> labNameList = labService.getLabNameList();

        return R.ok().put("list", labNameList);
    }


    /**
     * 信息
     */
    @Cacheable(value = "lab",key = "#id")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		LabEntity lab = labService.getById(id);

        return R.ok().put("lab", lab);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LabEntity lab){
		labService.save(lab);

        return R.ok();
    }

    /**
     * 修改
     */
    @CachePut(value = "lab", key = "#lab.id")
    @RequestMapping("/update")
    public R update(@RequestBody LabEntity lab){
		labService.updateById(lab);

        return R.ok();
    }

    /**
     * 删除
     */
    @CacheEvict(value = "lab",key = "#ids")
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		labService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
